package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 使用预编译SQL完成更新操作
 * 根据id修改用户的密码，昵称，年龄
 */
public class Demo10 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();) {
            String sql = "UPDATE user " +
                         "SET password=?,nickname=?,age=? " +
                         "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"111111");
            ps.setString(2,"老四");
            ps.setInt(3,55);
            ps.setInt(4,6);
            int num = ps.executeUpdate();
            System.out.println(num>0?"插入成功":"插入失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
